<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYDCONN();
form_pr('RequestProperties','','','post');
	if($_GET['rqID']>0){
	
    $GET = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_requests.Ref,
					ccenter_requests.RefUser,
					ccenter_requests.Observations,
					ccenter_requests.TimeCreated,
					ccenter_requests.TimeDelivered,
					ccenter_requests.TimeReceived,
					ccenter_requests.TimeAproval,
					ccenter_requests.RefAproval,
					ccenter_requests.RefSupervisor,
					ccenter_requests.status,
					hcce_status.name AS Status,
					main_offices.name AS Office,
					main_users.name AS User
				FROM ccenter_requests
				INNER JOIN main_offices ON main_offices.ref = ccenter_requests.RefOffice
				INNER JOIN main_users ON main_users.ref = ccenter_requests.RefUser
				INNER JOIN hcce_status ON hcce_status.ref = ccenter_requests.Status
				WHERE ccenter_requests.Ref = {$_GET['rqID']}
				ORDER BY ccenter_requests.TimeCreated DESC, ccenter_requests.Ref DESC LIMIT 0,1");	
	} else {
	
    $FGET = $GLOBALS['MYD']->db_array("DESCRIBE ccenter_requests"); 
    	for($i=1;$i<=$FGET[0];$i++) {
    		$GET[1][$FGET[$i]['Field']] = '';
    	}
    	$GET[1]['Ref'] = 0;
    	$GET[1]['User'] = $_SESSION[$SESSUS];
    	$GET[1]['Office'] = $_SESSION[$SESSCD];
    	$GET[1]['TimeCreated'] = date("Y-m-d");
    	$GET[1]['status'] = 0;
	} ?>
<table width="100%"  border="0" cellspacing="1" cellpadding="3">
  <tr>
    <td width="25%" rowspan="2" rowspan="4" bgcolor="#ACB1CC"><div align="right">
	<img src="<?php echo $GLOBALS['GFX'];?>CentrodeCustos/requests.png"></div></td>
    <td bgcolor="#ACB1CC">Pedido no. <?php mn_field('text','ED','Ref',$GET[1]['Ref'],'6','6','','" readonly="'); ?>
    | Data: <?php echo $GET[1]['TimeCreated'];?> | Requerente: <?php echo $GET[1]['Office'];?>, Por: <?php echo $GET[1]['User'];?></td>
  </tr>
  <tr><td bgcolor="#ACB1CC">ObservaÇ&otilde;es<br>
  <?php mn_field('textarea','ED','Observations',$GET[1]['Observations'],'80','3','',''); ?></td></tr>
  <tr bgcolor="#F2F2F2">
    <td colspan="2" height="290"><div id="reqItems" style="height:290;overflow:auto;">
 <?php include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/list_requests_article.php'); ?></div></td>
  </tr>
  <tr bgcolor="#ACB1CC">
    <td height="70" colspan="2"><div id="respRequest" style="float:right"></div>
	<div style="margin:10px">Estado: <?php echo $GET[1]['Status'];?></div>
    	<div style="margin:6px"><?php if ($GET[1]['TimeAproval'] =! null) {
  	echo 'Aprovação: ';
     if ($GET[1]['RefAproval'] > 0) { $GET[1]['RefAproval'].', a '.$GET[1]['TimeAproval']; } 
	else { echo 'A aguardar aprovação'; }
	 } ?></div>
    	<div style="margin:6px"><?php
    	if ($GET[1]['TimeDelivered'] != null) { 
	echo 'Data Para Entrega '.$GET[1]['TimeAproval'];
	}
  if ($GET[1]['TimeDelivered'] != null && $GET[1]['TimeReceived'] == null) {
		mn_field('date','ED','DateReceived',$_POST['TimeReceived'],'','8','','');
	} else {
	echo $GET[1]['TimeReceived'];
	} ?></div>
	<div style="margin:6px"><?php 
	if($GET[1]['status'] == 0) {
	mn_field('button','ED','reqSubmit','Submeter','','','','"
			onClick="document.RequestProperties.action=\'_response/rsproxy.php?act=1&pr=cdc_requests\';
					subform(\'RequestProperties\',\'respRequest\');');
	} elseif($GET[1]['status'] == 3) {
	mn_field('button','ED','reqSubmit','Confirmar Recebimento','','','','"
			onClick="document.RequestProperties.action=\'_response/rsproxy.php?act=6&pr=cdc_requests\';
					subform(\'RequestProperties\',\'respRequest\');');
	}
	?></div>
	</td>
  </tr>
</table>
</form>